<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
	

   
  <ul class="forminfo forminfo_mobile" style="margin-top: 20px;">
    	<li><label>变更前实习单位</label><div class="label_right  label_right_mobile">
    		<c:if test="${jobStudent.status==0}">在校</c:if>
			<c:if test="${jobStudent.status==1}">自主创业</c:if>
			<c:if test="${jobStudent.status==2}">专升本</c:if>
			<c:if test="${jobStudent.status==3}">自寻企业实习</c:if>
			<c:if test="${jobStudent.status==4}">学校分配企业</c:if>  - ${jobStudent.enterpriseName }</div></li>
    	<li><label>变更前实习时间</label><div class="label_right  label_right_mobile">${jobStudent.startTime}至${jobStudent.endTime}</div></li>
    	<li><label>变更后实习类别</label>
    	<select class="forminfo_select" name="Status" id="Status" onchange="selectChanged();" style="width: 150px;" >
								     	<option value="4">学校分配实习</option>
								     	<option value="3">自训企业</option>
								     	<option value="2">专升本</option>
								     	<option value="1">创业</option>
								</select> 
    	</li>
    	<div id="Entrepreneurship">	
    	 <li><label>创业单位</label><input name="EnterpriseName" id="entrepreneurshipEnterpriseName" type="text" class="dfinput" maxlength="20"></li>
    	</div>
    	<div id="Self">	
    	 <li><label>实习单位</label><input name="EnterpriseName" id="selfEnterpriseName" type="text" class="dfinput" maxlength="30"></li>
    	 <li><label>单位地址</label><input name="TheAddress" type="text" class="dfinput" maxlength="40"></li>
    	 <li><label>企业联系人</label><input  type="text" class="dfinput" name="TheContact" maxlength="10"></li>
    	  <li><label>企业联系人电话</label><input  type="text" class="dfinput" name="TheContactPhone" maxlength="15" id="TheContactPhone" onblur="phoneOnblur();"></li> 
    	  </div>
    	  <div id="schoolAssignment">
    	  <li><label>实习单位</label>省份：<select id="dpselect" name="TheProvince" class="forminfo_select forminfo_select_mobile" onchange="TheProvince();">
							<c:forEach items="${provinceList}" var="province">
							<option value="${province.provinceId }" >${province.provinceName }</option>
						</c:forEach>
						</select><br>
						<div style="margin-left: 100px;" >
							城市：<select id="TheCity" name="TheCity" class="forminfo_select forminfo_select_mobile"  onchange="TheCity();">
							<c:forEach items="${cityList}" var="city">
							<option value="${city.cityId }"  >${city.cityName }</option>
						</c:forEach>
					</select>
					</div>
					<div style="margin-top:10px;" >
					单位：<select id="EnterpriseId" name="EnterpriseId" class="forminfo_select1 "  onchange="enterpriseinfo();">
						<c:forEach items="${enterpriseinfoList}" var="enterpriseinfoList">
							<option value="${enterpriseinfoList.id }" >${enterpriseinfoList.name }</option>
						</c:forEach>
					</select>
					</div>
			</li>
    	  <li><label>实习岗位</label><select class="forminfo_select forminfo_select_mobile" name="JobId" id="JobId">
								     	<option value="黎明"> -- 待定 -- </option>
								     	<c:forEach items="${jobInfoList}" var="jobInfo">
							<option value="${jobInfo.id }" >${jobInfo.jobName }</option>
						</c:forEach>
								</select> </li>
    	  <li><label>企业指导老师</label><select class="forminfo_select forminfo_select_mobile" name="UserAccount" id="EnterTeacherId">
								     <c:forEach items="${enterpriseUserList}" var="enterpriseUser">
							<option value="${enterpriseUser.userAccount}" >${enterpriseUser.userName }</option>
						</c:forEach>
								</select> </li>
		</div>
		<li><label>学校指导老师</label><select class="forminfo_select forminfo_select_mobile" name="ZGH" id="ZGH">
								     	  <c:forEach items="${teacherInfoList}" var="teacherInfo">
							<option value="${teacherInfo.ZGH }" >${teacherInfo.XM }</option>
						</c:forEach>
								</select> </li>
    	<li><label>申请变更时间</label><input name="startTime" id="startTime" type="text" class="dfinput dfinput_mobile" onclick="SelectDate(this,'yyyy-MM-dd')">至<input name="endTime" id="endTime" type="text" class="dfinput dfinput_mobile" onclick="SelectDate(this,'yyyy-MM-dd')"></li>
    	<li><label>变更申请理由</label><textarea class="textinput textinput_mobile " name="applyCause" maxlength="100"></textarea></li>
	<li><label>&nbsp;</label><input name="" type="button" onclick="submitForm()" class="btn" value="申请"/></li>
    </ul>
</body>
  	<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
  	 <script type="text/javascript" src="js/adddate.js"></script>
    <script type="text/javascript" src="js/jquery.tips.js"></script>
     <script src="layer/layer.js"></script>
<script type="text/javascript" >
var a = new Date();
var month = a.getMonth()+1;
if(month<10){
	month = "0" +month;
}
var day = a.getDate();
if(day<10){
	day = "0" + day;
}
$("#startTime").val(a.getFullYear()+"/"+month+"/"+day);
$("#endTime").val(a.getFullYear()+"/"+month+"/"+day);

$("#Self").hide();
$("#Entrepreneurship").hide();
$("#schoolAssignment").show();
function selectChanged() {
	 var ele=document.getElementById('Status');
  	 var index=ele.selectedIndex;
 	 var val=ele.options[index].value;
 	 if(val==4){
 		$("#Self").hide();
 		$("#Entrepreneurship").hide();
		$("#schoolAssignment").show();
 	 }else if(val==3||val==2){
 		$("#Self").show();
 		$("#Entrepreneurship").hide();
		$("#schoolAssignment").hide();
 	 }else {
 		$("#Self").hide();
 		$("#Entrepreneurship").show();
		$("#schoolAssignment").hide();
	}
 	 
 	 }
function TheProvince() {
	 var ele=document.getElementById('dpselect');
	  	var index=ele.selectedIndex;
	 	 var val=ele.options[index].value;
	 	$.ajax({
		type: "POST",
		url: "jobStudent/province.do",
		data: { ProvinceId : val},
		async: true,
		dataType: "json",
		success: function(data) {
			$("#TheCity").empty();
			for(var i in data.cityList){  
				var $str = "<option value="+data.cityList[i].cityId +">"+data.cityList[i].cityName +"</option>";
				$("#TheCity").append($str);  	 
			}
			$("#EnterpriseId").empty();
			for(var i in data.enterpriseinfoList){  
				var $str1 = "<option value="+data.enterpriseinfoList[i].userAccount +">"+data.enterpriseinfoList[i].name +"</option>";
				$("#EnterpriseId").append($str1);  	 
			}
			$("#UserAccount").empty();
			for(var i in data.enterpriseUserList){  
				var $str2 = "<option value="+data.enterpriseUserList[i].id +">"+data.enterpriseUserList[i].userName +"</option>";
				$("#UserAccount").append($str2);  	 
			}
		}
		})
		}
function TheCity() {
	 var ele=document.getElementById('TheCity');
	  	var index=ele.selectedIndex;
	 	 var val=ele.options[index].value;
	 	$.ajax({
		type: "POST",
		url: "jobStudent/city.do",
		data: { cityId : val},
		async: true,
		dataType: "json",
		success: function(data) {
			$("#EnterpriseId").empty();
			for(var i in data.enterpriseinfoList){  
				var $str = "<option value="+data.enterpriseinfoList[i].id +">"+data.enterpriseinfoList[i].name +"</option>";
				$("#EnterpriseId").append($str);  	 
			}
			$("#UserAccount").empty();
			for(var i in data.enterpriseUserList){  
				var $str1 = "<option value="+data.enterpriseUserList[i].id +">"+data.enterpriseUserList[i].userName +"</option>";
				$("#UserAccount").append($str1);  	 
			}
		}
	})
}
function enterpriseinfo() {
	 var ele=document.getElementById('EnterpriseId');
	  	var index=ele.selectedIndex;
	 	 var val=ele.options[index].value;
	 	$.ajax({
		type: "POST",
		url: "jobStudent/enterpriseinfo.do",
		data: { EnterpriseId : val},
		async: true,
		dataType: "json",
		success: function(data) {
			$("#UserAccount").empty();
			for(var i in data.enterpriseUserList){  
				var $str = "<option value="+data.enterpriseUserList[i].id +">"+data.enterpriseUserList[i].userName +"</option>";
				$("#UserAccount").append($str);  	 
			}
		}
	})
}
function phoneOnblur(){
 	var inp = document.getElementById("TheContactPhone");
	var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
	var result = reg.test(inp.value);
	if (!result) {
		showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
		return false;
	}
}
function submitForm() {
	var ele=document.getElementById('Status');
  	 var index=ele.selectedIndex;
 	 var Status=ele.options[index].value;
 	 if(Status==3||Status==2){
		if ($("#selfEnterpriseName").val()=="") {
			$("#selfEnterpriseName").tips({
				side : 1,
				msg : '	请填写实习单位',
				bg : '#0099FF',
				time : 3
			});
			return false;
		}
		if ($("input[name='TheAddress']").val() == "") {
			showTips($("input[name='TheAddress']"), '请填写单位地址!');
			return false;
		}
		if ($("input[name='TheContact']").val() == "") {
			showTips($("input[name='TheContact']"), '请填写企业联系人!');
			return false;
		}
		
		if ($("input[name='TheContactPhone']").val() =="") {
			showTips($("input[name='TheContactPhone']"), '请填写企业联系人电话!');
			return false;
		}
		if ($("textarea[name='applyCause']").val() =="") {
			showTips($("textarea[name='applyCause']"), '请填写申请理由!');
			return false;
		}
		var inp = document.getElementById("TheContactPhone");
		var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
		var result = reg.test(inp.value);
		if (!result) {
			showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
			return false;
		}
			if($("#startTime").val()==''){
				showTips($("input[name='startTime']"), '请选择开始时间!');
				return false;
			}
			if($("#endTime").val()==''){
				showTips($("input[name='endTime']"), '请选择结束时间!');
				return false;
			}
			var e = $.trim($("#startTime").val());
			var f = $.trim($("#endTime").val());
			if(e>f){
			    	showTips($("input[name='endTime']"), '开始时间要迟于结束时间!');
			    	 return false;
			 }
			 var ele=document.getElementById('ZGH');
			  	var index=ele.selectedIndex;
			 	 var val=ele.options[index].value;
				$.ajax({
					type : "POST",
					url : "practiceChange/selfEnterprise_save.do",
					data : {
						Status : Status,
						EnterpriseName : $("#selfEnterpriseName").val(),
						TheAddress : $("input[name='TheAddress']").val(),
						TheContact : $("input[name='TheContact']").val(),
						TheContactPhone : $("input[name='TheContactPhone']").val(),
						SchoolTeacher : val,
						applyCause :$("textarea[name='applyCause']").val(),
						startTime :$("input[name='startTime']").val(),
						endTime : $("input[name='endTime']").val()
						},
					async : true,
					dataType : "json",
					success : function(data) {
						if ("success" == data.result) {
							parent.closeAll();
						} else {
							layer.alert('申请失败!', {
								skin : 'layer-ext-moon'
							});
						}
					}
				})
	} else if (Status==1) {
		if ($("#entrepreneurshipEnterpriseName").val()=="") {
			$("#entrepreneurshipEnterpriseName").tips({
				side : 1,
				msg : '	请填写创业单位',
				bg : '#0099FF',
				time : 3
			});
			return false;
		}
		if ($("textarea[name='applyCause']").val() =="") {
			showTips($("textarea[name='applyCause']"), '请填写申请理由!');
			return false;
		}
		if($("#startTime").val()==''){
			showTips($("input[name='startTime']"), '请选择开始时间!');
			return false;
		}
		if($("#endTime").val()==''){
			showTips($("input[name='endTime']"), '请选择结束时间!');
			return false;
		}
		var e = $.trim($("#startTime").val());
		var f = $.trim($("#endTime").val());
		 if(e>f){
		    	showTips($("input[name='endTime']"), '开始时间要迟于结束时间!');
		    	 return false;
		    }
		 var ele=document.getElementById('ZGH');
		  	var index=ele.selectedIndex;
		 	 var val=ele.options[index].value;
		    $.ajax({
				type : "POST",
				url : "practiceChange/entrepreneurshipEnterprise_save.do",
				data : {
					EnterpriseName : $("#entrepreneurshipEnterpriseName").val(),
					SchoolTeacher : val,
					applyCause :$("textarea[name='applyCause']").val(),
					startTime : $("input[name='startTime']").val(),
					endTime : $("input[name='endTime']").val()},
				async : true,
				dataType : "json",
				success : function(data) {
					if ("success" == data.result) {
						parent.closeAll();
					} else {
						layer.alert('申请失败!', {
							skin : 'layer-ext-moon'
						});
					}
				}
			})
	}else{
		if($("#startTime").val()==''){
			showTips($("input[name='startTime']"), '请选择开始时间!');
			return false;
		}
		if($("#endTime").val()==''){
			showTips($("input[name='endTime']"), '请选择结束时间!');
			return false;
		}
		if ($("textarea[name='applyCause']").val() =="") {
			showTips($("textarea[name='applyCause']"), '请填写申请理由!');
			return false;
		}
		var e = $.trim($("#startTime").val());
		 var f = $.trim($("#endTime").val());
		    if(e>f){
		    	showTips($("input[name='endTime']"), '开始时间要迟于结束时间!');
		    	 return false;
		    }
		   
					var EnterpriseId = document.getElementById('EnterpriseId');
					var index1 = EnterpriseId.selectedIndex;
					var enterpriseId = EnterpriseId.options[index1].value;
					var JobId = document.getElementById('JobId');
					var index2 = JobId.selectedIndex;
					var jobId = JobId.options[index2].value;
					var EnterTeacherId=document.getElementById('EnterTeacherId');
				  	var i=EnterTeacherId.selectedIndex;
				 	 var enterTeacherId =EnterTeacherId.options[i].value;
					var ZGH=document.getElementById('ZGH');
				  	var index4=ZGH.selectedIndex;
				 	 var zgh =ZGH.options[index4].value;
				  $.ajax({
						type : "POST",
						url : "practiceChange/school_assignment.do",
						data : {
							PracticeEnterprise : enterpriseId,
							EnterTeacherId : enterTeacherId,
							JobId : jobId,
							applyCause :$("textarea[name='applyCause']").val(),
							SchoolTeacher : zgh,
							startTime : $("input[name='startTime']").val(),
							endTime : $("input[name='endTime']").val()
						},
						async : true,
						dataType : "json",
						success : function(data) {
							if ("success" == data.result) {
								parent.closeAll();
							} else {
								layer.alert('申请失败!', {
									skin : 'layer-ext-moon'
								});
							}
						}
					})   
				}
			}
	function showTips(obj,tips) {
		obj.tips({
			side:3,
	        msg:tips,
	        bg:'#e69138',
	        time:2
	    });
	}

</script>
</html>
